//aboutus
//  huiyuanDetailsViewController.m
//  daogouApp
//
//  Created by panquanReabam.com on 15-6-2.
//  Copyright (c) 2015年 jiezsoft.com. All rights reserved.
//

#import "AboutUsViewController.h"
#import "HttpRequest.h"
#import "TagView.h"
#import "UIViewExt.h"
#import "RDVTabBarController.h"
#import "MJRefresh.h"
#import <JavaScriptCore/JavaScriptCore.h>
#import "ExhibitionObject.h"
#import "UMSocial.h"
#import "ToBindCompanyViewController.h"
#import "ShareView.h"
@interface AboutUsViewController ()<MBProgressHUDDelegate,TestDelegate,UIGestureRecognizerDelegate,UIWebViewDelegate,UINavigationControllerDelegate,UITextFieldDelegate,UMSocialUIDelegate,ShareViewDelegate>
@property(nonatomic,strong)   NSString*shuoming;
@property(nonatomic,strong)   NSString*shareUrl;

@end

@implementation AboutUsViewController


{

    ShareView*SV;
    UIView*shareblackview;
    UIScrollView*MYmainScroll;
    UIWebView*webview;
    NSDictionary*dic;

}

@synthesize alt = alt;
-(void)BackAction:(UIButton *)sender{
    
    
    [self.navigationController popViewControllerAnimated:YES];
    
}
- (void)viewDidDisappear:(BOOL)animated

{
    
    [super viewDidDisappear:animated];
    
    
    
    self.navigationController.delegate = nil;
    
}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [[self rdv_tabBarController] setTabBarHidden:YES];
   
    self.navigationController.navigationBarHidden=NO;
    self.navigationController.navigationBar.barStyle = UIBaselineAdjustmentNone;
    UILabel *lineLabel=[[UILabel alloc] initWithFrame:CGRectMake(0, 43,ScreenWidth, 1)];
    [lineLabel setBackgroundColor:[UIColor colorWithRed:238.0/255.0 green:238.0/255.0 blue:238.0/255.0 alpha:1.0]];
    [self.navigationController.navigationBar addSubview:lineLabel];
    [self.navigationController.navigationBar setTintColor:[UIColor whiteColor]];
    [[UINavigationBar appearance] setBarTintColor:Color];
    
    UIImage* backImage = [UIImage imageNamed:@"fanhui"];
    CGRect backframe = CGRectMake(0,0,30,30);
    UIButton* backButton= [[UIButton alloc] initWithFrame:backframe];
    [backButton setBackgroundImage:backImage forState:UIControlStateNormal];
    backButton.titleLabel.font=[UIFont systemFontOfSize:13];
    [backButton addTarget:self action:@selector(BackAction:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem* leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
    self.navigationItem.leftBarButtonItem = leftBarButtonItem;
    self.navigationController.delegate = self;
    
    self.navigationController.interactivePopGestureRecognizer.delegate = self;
    
    
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed: @""] forBarMetrics:UIBarMetricsDefault];
    self.navigationController.navigationBar.shadowImage = [[UIImage alloc] init];
    
    
    
    UIButton* sxBtn = [[UIButton alloc] initWithFrame:CGRectMake(30, 0.0,  60/2, 60/2)];
    [sxBtn setImage:[UIImage imageNamed:@"fenxiang"] forState:UIControlStateNormal];
    [sxBtn addTarget:self action:@selector(share:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem* myBtnBtn = [[UIBarButtonItem alloc] initWithCustomView:sxBtn];
    self.navigationItem.rightBarButtonItem = myBtnBtn;

    
    
    
    
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
  
    self.title = @"关于我们";
    
    [self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                                                                     backColor,
                                                                     UITextAttributeTextColor,
                                                                     [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:1],
                                                                     UITextAttributeTextShadowColor,
                                                                     [NSValue valueWithUIOffset:UIOffsetMake(0, 0)],
                                                                     UITextAttributeTextShadowOffset,
                                                                     [UIFont fontWithName:@"Helvetica Neue" size:tetlefot],
                                                                     UITextAttributeFont,nil]];

    
    webview  = [[UIWebView   alloc]  initWithFrame:CGRectMake( 0,  0,  ScreenWidth ,  ScreenHeight)];
    webview.scalesPageToFit = TRUE;
    [webview   setUserInteractionEnabled: YES ];	 //是否支持交互
    [webview   setDelegate: self ];				 //委托
    [webview   setOpaque: YES ];
    [webview setNeedsLayout];
    [webview layoutIfNeeded];//透明
    [self.view  addSubview : webview];
    [self loadPage];
    
    
    
}

- (void)loadPage {
    

    NSInteger numtime = [NSDate date].timeIntervalSince1970;
    NSString *numtimestr = [NSString stringWithFormat:@"%ld",numtime];
    NSString *str1=[NSString stringWithFormat:@"%d",TARGET_VERSION];
    NSString *plistPath1 = [[NSBundle mainBundle] pathForResource:str1
                                                           ofType:@"plist"];
    NSDictionary *dictionary1 = [[NSDictionary alloc] initWithContentsOfFile:plistPath1];
//    NSLog(@"dictionary1===%@",dictionary1);
    NSString *serverAddress = [dictionary1 objectForKey:@"ExhibitionUrlHead"];
    NSString *urlStr=[NSString stringWithFormat:@"%@/htmlForApp/aboutus.html?v=%@",serverAddress,numtimestr];
    NSURL *url = [[NSURL alloc]initWithString:urlStr];
    [webview loadRequest:[NSURLRequest requestWithURL:url]];
//    NSLog(@"-----%@",urlStr);
}

- (void)webViewDidStartLoad:(UIWebView *)webView
{
    
    
    JSContext *context=[webView valueForKeyPath:@"documentView.webView.mainFrame.javaScriptContext"];
    
    //js调用iOS
    //第一种情况
    //其中test1就是js的方法名称，赋给是一个block 里面是iOS代码
    
    ExhibitionObject *exhiObject=[ExhibitionObject  new];
    exhiObject.delegate=self;
    context[@"appJs"]=exhiObject;
    
    
}
-(void)closeKeyBoad
{
    [self.window makeKeyWindow];
    self.window.hidden=YES;
    [SV removeFromSuperview];
    
}
-(void)cancel:(NSString *)cancel{
    [self closeKeyBoad];
}

-(void)share:(UIButton*)sender{
    
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    NSString* Token = [user objectForKey:@"tokenId"];
    NSMutableDictionary *param = [NSMutableDictionary new];
    [param setValue:Token forKey:@"tokenId"];
    [param setValue:@"aboutus" forKey:@"contentType"];
    [param setValue:@"" forKey:@"contentId"];
    [param setValue:@"wx_single" forKey:@"shareTarget"];
    [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
    [HttpRequest requestData:@"Company/getShareUrl" params:param success:^(BOOL isSuccess, SeverData *severDataDict) {
        if (isSuccess) {
            
            NSLog(@"====%@",severDataDict.dataDict);
            if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                [Global hideProgressHUDInternal:self.view];
                self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
                [self.window makeKeyAndVisible];
                
                shareblackview=[[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight)];
                shareblackview.backgroundColor=[UIColor blackColor];
                shareblackview.alpha=0.65;
                [self.window addSubview:shareblackview];
                
                SV = [[ShareView alloc]initWithFrame:CGRectMake(0, ScreenHeight-245, ScreenWidth,245)];
                SV.dataDict=severDataDict.dataDict;
                
                SV.mDelegate=self;
                [self.window addSubview:SV];
                
                UITapGestureRecognizer *singleFingerOne = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(closeKeyBoad)];
                singleFingerOne.numberOfTouchesRequired = 1; //手指数
                singleFingerOne.numberOfTapsRequired = 1; //tap次数
                singleFingerOne.delegate = self;
                [shareblackview addGestureRecognizer:singleFingerOne];
                
                
            }else{
                [Global hideProgressHUDInternal:self.view];
                if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==8888) {
                    ToBindCompanyViewController * Login=[[ToBindCompanyViewController alloc]init];
                    [self.navigationController pushViewController:Login animated:YES];}
                if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==4444) {
                    [self showAlertMessage:@"账号信息未认证通过，请从新上传"];
                    ToBindCompanyViewController * Login=[[ToBindCompanyViewController alloc]init];
                    [self.navigationController pushViewController:Login animated:YES];
                    
                }
            }
            
        }
        else
        {
            [Global hideProgressHUDInternal:self.view];
            [Global showTextHudSub:severDataDict.resultStr view:self.view];
        }
        
    }];
}

    
//-(void)closeKeyBoad
//{
//    [shareview removeFromSuperview];
//    [shareScroll removeFromSuperview];
//    [cancel removeFromSuperview];
//    
//}
//-(void)fenxiangss:(UIButton*)sender{
//    
//
//    
//                self.shuoming=@"豪德汇，为互联网+家居建材商贸城打造的专业线上平台，实现进驻商户的线下门店与线上商铺同时运营，通过商品展示、内容运营、需求发布等吸引更多线上客源到店交易。平台更为商户们提供抱团采购和优质服务，提高商户的留存率和进驻率，最终实现传统商贸城互联网化和服务的转型升级。";
//                self.shareUrl=@"https://itunes.apple.com/cn/app/hao-de-hui/id1063993065?mt=8";
//                
//                shareview=[[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight)];
//                shareview.backgroundColor=[UIColor blackColor];
//                shareview.alpha=0.5;
//                [self.view addSubview:shareview];
//                
//                shareScroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0,ScreenHeight-240, ScreenWidth,200)];
//                shareScroll.delegate = self;
//                shareScroll.userInteractionEnabled = YES;
//                shareScroll.scrollEnabled = YES;
//                shareScroll.showsVerticalScrollIndicator = FALSE;
//                shareScroll.showsHorizontalScrollIndicator = FALSE;
//                shareScroll.backgroundColor=[UIColor whiteColor];
//                [self .view addSubview:shareScroll];
//                
//                // 手势
//                UITapGestureRecognizer *singleFingerOne = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(closeKeyBoad)];
//                singleFingerOne.numberOfTouchesRequired = 1; //手指数
//                singleFingerOne.numberOfTapsRequired = 1; //tap次数
//                singleFingerOne.delegate = self;
//                [shareview addGestureRecognizer:singleFingerOne];
//                NSArray*nameBtn=[[NSArray alloc]initWithObjects:@"发送給朋友",@"分享到朋友圈",nil];
//                NSArray *arrayimage = @[@"faweixin",@"fenxiangpenyouquan"];
//                for (int i = 0; i<2; i++) {
//                    UIButton *nameButcenter = [[UIButton alloc]initWithFrame:CGRectMake(ScreenWidth/3*i,   80*ScreenHeight/1334+15, ScreenWidth/3, 60)];
//                    
//                    [shareScroll addSubview:nameButcenter];
//                    
//                    
//                    UIButton *nameBut = [[UIButton alloc]initWithFrame:CGRectMake(ScreenWidth/3*i,   nameButcenter.bottom+20, ScreenWidth/3, 14)];
//                    [nameBut setTitle: [nameBtn objectAtIndex:i]  forState:UIControlStateNormal];
//                    nameBut.tag=201+i;
//                    [nameBut setTitleColor:shenhuiColor forState:0];
//                    nameBut.titleLabel.font=[UIFont systemFontOfSize:14];
//                    [nameBut addTarget:self action:@selector(share:) forControlEvents:UIControlEventTouchUpInside];
//                    [shareScroll addSubview:nameBut];
//                    
//                    
//                    UIButton *wuyebuttonimage = [UIButton buttonWithType:UIButtonTypeCustom];
//                    wuyebuttonimage.frame = CGRectMake(ScreenWidth/3*i,  10, 60, 60);
//                    
//                    wuyebuttonimage.tag = 201+i;
//                    wuyebuttonimage.center=nameButcenter.center;
//                    [wuyebuttonimage setImage:[UIImage imageNamed: [arrayimage objectAtIndex:i]] forState:UIControlStateNormal];
//                    [wuyebuttonimage addTarget:self action:@selector(share:) forControlEvents:UIControlEventTouchUpInside];
//                    [shareScroll addSubview:wuyebuttonimage];
//                    
//                    
//                }
//                
//                
//                cancel = [[UIButton alloc] initWithFrame:CGRectMake(0,ScreenHeight-45,  ScreenWidth, 45)];
//                [cancel setTitle:@"取消" forState:UIControlStateNormal];
//                cancel.titleLabel.font=[UIFont systemFontOfSize:15];
//                cancel.backgroundColor=[UIColor whiteColor];
//                [cancel setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
//                [cancel addTarget:self action:@selector(closeKeyBoad) forControlEvents:UIControlEventTouchUpInside];
//                [self .view addSubview:cancel];
//                UILabel*line11=[[UILabel alloc]initWithFrame:CGRectMake(15, 0, ScreenWidth-30, 0.40)];
//                line11.backgroundColor=qianhuiColor;
//                [cancel addSubview:line11];
//                
//                
//                
//
//    
//    
//    
//}
//
//-(void)share:(UIButton*)sender{
//    [shareview removeFromSuperview];
//    [shareScroll removeFromSuperview];
//    [cancel removeFromSuperview];
//   
//    UIImage *image1 = [UIImage imageNamed:@"120x120logos.png"];
//    if (sender.tag==201) {
//        
//        [UMSocialData defaultData].extConfig.wechatSessionData.title = @"豪德汇";
//        UMSocialUrlResource *urlResource = [[UMSocialUrlResource alloc] initWithSnsResourceType:UMSocialUrlResourceTypeDefault url:self.shareUrl];
//        
//        [UMSocialSnsPlatformManager getSocialPlatformWithName:UMShareToWechatSession].snsClickHandler(self,[UMSocialControllerService defaultControllerService],YES);
//        [UMSocialData defaultData].extConfig.wechatSessionData.url = self.shareUrl;
//        [[UMSocialDataService defaultDataService]postSNSWithTypes:@[UMShareToWechatSession] content:self.shuoming image:image1 location:nil urlResource:urlResource presentedController:self completion:^(UMSocialResponseEntity *response){
//            
//            if (response.responseCode == UMSResponseCodeSuccess) {
//                NSLog(@"分享成功！");
//            }
//            
//        }];
//        
//        
//        
//        
//        
//        
//    }
//    
//    if (sender.tag==202) {
//        
//        //         [UMSocialData defaultData].extConfig.wechatSessionData.title =[commdity.Dict objectForKey:@"itemName"];
//        UMSocialUrlResource *urlResource = [[UMSocialUrlResource alloc] initWithSnsResourceType:UMSocialUrlResourceTypeDefault url:self.shareUrl];
//        [UMSocialSnsPlatformManager getSocialPlatformWithName:UMShareToWechatTimeline].snsClickHandler(self,[UMSocialControllerService defaultControllerService],YES);
//        [UMSocialData defaultData].extConfig.wechatTimelineData.url = self.shareUrl;
//        [[UMSocialDataService defaultDataService]  postSNSWithTypes:@[UMShareToWechatTimeline] content:[NSString stringWithFormat:@"%@",   @"豪德汇"] image:image1 location:nil urlResource:urlResource presentedController:self completion:^(UMSocialResponseEntity *response){
//            if (response.responseCode == UMSResponseCodeSuccess) {
//                NSLog(@"分享成功！");
//            }
//        }];
//        
//        
//        
//        
//    }
//    
//}

- (void)showAlertWait
{
    alt = [[UIAlertView alloc] initWithTitle:@"网络不稳定 ！" message:@"请确认网络" delegate:self cancelButtonTitle:nil otherButtonTitles: nil];
    [alt show];
    
    [self performSelector:@selector(hideAlert) withObject:nil afterDelay:1.0f];
    
}

- (void)showAlertMessage:(NSString *)msg
{
    alt = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:msg delegate:nil cancelButtonTitle:nil otherButtonTitles: nil];
    [alt show];
    
    [self performSelector:@selector(hideAlert) withObject:nil afterDelay:1.0f];
}
- (void)hideAlert
{
    if (alt != nil)
    {
        [alt dismissWithClickedButtonIndex:0 animated:YES];
        alt = nil;
    }
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
